
#include "Chart.h"
#include <math.h>


Chart::Chart(int dim, double **limits, int num_slices)
{
	_dim = dim;
	_limits = limits;

	_num_rows = num_slices;
	_increments = (double *) calloc (_num_rows, sizeof(double));

	_table = vtkSmartPointer<vtkTable>::New();

	_initialize_increments();
	_add_domain_to_table();
}


Chart::~Chart()
{
	free(_increments);
}


void
Chart::_add_domain_to_table()
{
	int i, j;

	for (i = 0; i < _dim; i++)
	{
		vtkSmartPointer<vtkFloatArray> domain = vtkSmartPointer<vtkFloatArray>::New();

		char *name = (char *) calloc (32, sizeof(char));
		sprintf(name, "Axis %d", i);
		domain->SetName(name);

		_table->AddColumn(domain);
	}
}


void
Chart::_initialize_increments()
{
	for (int i = 0; i < _dim; i++)
		_increments[i] = (_limits[i][1] - _limits[i][0]) / ((double) _num_rows);
}

